import i18n from '@/lang'

// 期限单元选择
export const perioUnitSelect = [
  { label: 'common.minute', value: 'minute' },
  { label: 'common.day', value: 'day' },
  { label: 'common.week', value: 'week' },
  { label: 'common.month', value: 'month' },
  { label: 'common.year', value: 'year' }
]


var statusLang = i18n.messages[i18n.locale]['status']
statusLang = statusLang ? statusLang : {}
// 状态选择
export const statusSelect = [
  { key: 1, value: 1, label: 'enabled' in statusLang ? statusLang['enabled'] : 'enabled'},
  { key: 0, value: 0, label: 'disabled' in statusLang ? statusLang['disabled'] : 'disabled'}
]

var recommended = i18n.messages[i18n.locale]['recommended']
recommended = recommended ? recommended : {}
export const recommendedSelect = [
  { key: 1, value: 1, label: 1 in recommended ? recommended[1] : 1},
  { key: 0, value: 0, label: 0 in recommended ? recommended[0] : 0}
]

// 客户端选择
export const clientSelect = [
  { value: 'web', label: 'web' },
  { value: 'wechat', label: 'wechat' },
  { value: 'android', label: 'android' },
  { value: 'ios', label: 'ios' }
]

// 用户等级
export const userLevel = [
  { key: 'testlevel1', value: 'testlevel1', label: 'testlevel1' },
  { key: 'testlevel2', value: 'testlevel2', label: 'testlevel2' },
  { key: 'testlevel3', value: 'testlevel3', label: 'testlevel3' }
]

// 混入
export const mixinDialog = {
  data() {
    return {
      list: {},
      loading: false,
      dialogFormVisible: false,
      isCreate: false,
      rules: undefined
    }
  },
  methods: {
    handleCreate() {
      this.formData = Object.assign({}, this.resetData)
      this.isCreate = true
      this.dialogFormVisible = true
    },
    handleEdit(row) {
      this.formData = Object.assign({}, row)
      this.dialogFormVisible = true
    },
    closeDialog() {
      this.formData = Object.assign({}, this.resetData)
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
      this.dialogFormVisible = false
      this.isCreate = false
    },
    submitDataBefore(isCheck, cb) {
      isCheck ? this.$refs.dataForm.validate(_ => _ && cb()) : cb()
    }
  }
}

// js获取时间时间戳（s）
export const currentStartWeekTime = new Date(new Date(new Date().toLocaleDateString()).getTime() - 7 * 24 * 60 * 60 * 1000) // 一周前
export const currentStartTime = new Date(new Date(new Date().toLocaleDateString()).getTime()) // 当天起始值
export const endStartTime = new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1000) // 当天结束值
export const currentGMT = () => {
  let str = new Date().toString()
  const index = str.lastIndexOf('GMT')
  str = str.substring(index + 3, index + 8)
  return str
}
